//
// Created by wang on 2021/7/1.
//

#ifndef ENET_DEV_H
#define ENET_DEV_H

#include "etypes.h"
#include <pthread.h>
#include "mp.h"

#define DEV_MAX_PIP_NAME_LEN 64
#define DEV_PORT_UP 1
#define DEV_PORT_DOWN 0

#define DEV_PKT_CACHE_BLOCK_SIZE 300
#define DEV_PKT_CACHE_BLOCK_NUM 10

#define DEV_PKT_BUFFER_BLOCK_SIZE DEV_PKT_CACHE_BLOCK_SIZE
#define DEV_PKT_BUFFER_BLOCK_NUM 800

typedef struct {
    char uni_name[DEV_MAX_PIP_NAME_LEN];
} dev_port_pipe;

typedef struct {
    uint8_t *cache;
    uint32_t len;
}cache_info;

typedef struct {
    cache_info cache_info[DEV_PKT_CACHE_BLOCK_NUM];
    mp_id pool_id;
    uint32_t blk_sz;
    uint32_t blk_n;
    uint32_t blk_w;
    uint32_t blk_r;
} pkt_cache;

typedef struct {
    uint8_t id;
    uint8_t state;
    dev_port_pipe pp;
    pthread_t tid;
    pkt_cache rx_cache;
    pkt_cache tx_cache;
} dev_port;

typedef struct {
    ip_node ip;
    uint8_t port_num;
    dev_port *ports;
}dev_info;

typedef struct {
    uint8_t *pkt;
    uint32_t len;
    uint32_t block_n;
} pkt_buffer;

typedef struct{
    uint32_t pkt_buf_sz;
    uint32_t pkt_buf_n;
    mp_id pool_id;
    pthread_t tid;
} pkt_analyzer;

void dev_init();
void de_init_dev();
void log_dev_info();
void get_dev_ip(ip_node *);
#endif //ENET_DEV_H
